home *** CD-ROM | disk | FTP | other *** search
/ MacPeople 2001 June 15 / MACPEOPLE-2001-06-15.ISO.7z / MACPEOPLE-2001-06-15.ISO / 連載データ / OS X情報局 / x-assist-03j.sit / X-Assist Japanese.dmg / X-Assist プラグイン SDK / SetVolume Example / XAPlugin.m < prev   
Text File  |  2001-04-17  |  3KB  |  127 lines

  1. //
  2. //  Plugin.m
  3. //  MyPlugin
  4. //
  5. //  Created by rosst on Fri Apr 13 2001.
  6. //  Copyright (c) 2001 __CompanyName__. All rights reserved.
  7. //
  8.  
  9. #import "XAPlugin.h"
  10. #include <Carbon/Carbon.h>
  11.  
  12. // ============================
  13. // == Change "SetVolume" below to your plugin name.
  14. // == Once you build the plugin, place it into the "X-Assist Plugins" folder
  15. // == and everything should just load.
  16. // == NOTE: you MUST use a unique name, otherwise the conflicting plugins
  17. // ==       will NOT load.
  18. // ============================
  19.  
  20. @implementation SetVolume
  21.  
  22. - (id)init
  23. {
  24.     // init plugin internals...
  25.     mPluginMenuItem = NULL;
  26.     
  27.     // ===============================
  28.     // Your Initialization code here...
  29.     // ===============================
  30.     GetSysBeepVolume(&mCurVolume);
  31.     
  32.     // END Initialization code.
  33.     
  34.     return self;
  35. }
  36.  
  37. - (void)shutdownPlugin
  38. {
  39.     // ===============================
  40.     // Your Shutdown code here...
  41.     // ===============================
  42.     if (mPluginMenuItem != NULL)
  43.         [mPluginMenuItem release];
  44. }
  45.  
  46.  
  47. // Required Plugin Routines
  48.  
  49. - (NSMenuItem*)getMenuItem
  50. {
  51.     if (mPluginMenuItem == NULL)
  52.     {
  53.         mPluginMenuItem = [[NSMenuItem alloc] init];
  54.         
  55.         // ===============================
  56.         // Setup our Menu item to our specifications...
  57.         // ===============================
  58.         {
  59.             NSMenu*    subMenu = [[NSMenu alloc] init];
  60.             NSMenuItem*    anItem;
  61.             int        counter;
  62.             
  63.             [mPluginMenuItem setTitle:@"Set Volume"];
  64.             
  65.             // you could add your own menu item icon too... 
  66.             // [mPluginMenuItem setImage: myNSImage /* (NSImage *)menuImage */];
  67.             
  68.             for (counter = 0; counter < 11; counter++)
  69.             {
  70.                 anItem = [[NSMenuItem alloc] init];
  71.                 [anItem setTitle:[NSString stringWithFormat:@"%d", counter]];
  72.                 [anItem setEnabled:YES];
  73.                 [anItem setAction:@selector(DoSetVolumeTo:) ];
  74.                 [anItem setTarget:self];
  75.             
  76.                 [subMenu addItem:anItem];
  77.                 [anItem autorelease];
  78.             }
  79.             [mPluginMenuItem setSubmenu:subMenu];
  80.         }
  81.         // END setup.
  82.         // ===============================
  83.     }
  84.     
  85.     return mPluginMenuItem;
  86. }
  87.  
  88. // items below are for future use.
  89. - (int)getMenuItemInsertLocation
  90. {
  91.     return 0;    // default location.
  92. }
  93.  
  94. - (int)getPluginAPIVersion
  95. {
  96.     return 1;
  97. }
  98.  
  99. // return info & copyright etc.
  100. - (NSString*)getPluginDescription
  101. {
  102.     return @"SetVolume v0.1¥r¥rSets the SysBeep volume.";
  103. }
  104.  
  105. // put up config window...
  106. - (void)doConfigurePlugin
  107. {
  108.     
  109.     
  110. }
  111.  
  112.  
  113.  
  114.  
  115. // User routines
  116.  
  117. - (IBAction)DoSetVolumeTo:(id)sender
  118. {
  119.     mCurVolume = atoi([[sender title] cString]);
  120.     SetSysBeepVolume((long) (25.6 * mCurVolume));
  121.     SetDefaultOutputVolume((long) (25.6 * mCurVolume));
  122.     SysBeep(30);
  123. }
  124.  
  125.  
  126. @end
  127.